import {createRouter, createWebHistory, RouteRecordRaw} from 'vue-router'
// @ts-ignore
import nProgress from 'nprogress';
import 'nprogress/nprogress.css'

const routes: Array<RouteRecordRaw> = [
    {
        path: '/',
        redirect: '/Home'
    },
    {
        path: '/Home',
        component: () => import('../views/Home.vue'),
        children: [
            {
                path: '/Home/About',
                name: 'about',
                component: () => import('../views/About.vue'),
                meta: {
                    title: '关于我'
                }

            },
            {
                path: '/Home/Me',
                name: 'me',
                component: () => import('../views/Me.vue'),
                meta: {
                    title: '我的'
                }

            }
        ]
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes
})

// nProgress配置
router.beforeEach((to, from, next) => {
    nProgress.start();
    next();
})

router.afterEach(() => {
    nProgress.done();
})

nProgress.configure({
    // @ts-ignore
    ease: 'linear',
    speed: 500,
    showSpinner: true  // 是否使用进度环
});

export default router